package com.example.roadship;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.ksoap2.serialization.PropertyInfo;

import android.content.Context;
import android.util.Log;

import class_sources.WSandJson;
import class_sources.XMPPConnector;

public class UserMainHandler {
	
	public static final String TAG = "MyService";
	public static final String server = "159.253.33.172";
	public static String userName = "";
	public static String password = "";
	public static String session = "";
	public static XMPPConnector connector;
	private WSandJson wsHelper=new WSandJson();
	
	private ArrayList<HashMap<String, String>> friendList=new ArrayList<HashMap<String,String>>();
	private ArrayList<HashMap<String, String>> favoriteList=new ArrayList<HashMap<String,String>>();
	private ArrayList<HashMap<String, String>> historyList=new ArrayList<HashMap<String,String>>();
	private ArrayList<HashMap<String, String>> lastRequestList=new ArrayList<HashMap<String,String>>();
	
	
	public UserMainHandler(String userName , String password , String session , Context context) {
		this.userName = userName;
		this.password = password;
		this.session = session;
		
		/*Initialize User Properties*/
		setFavoriteList(initiliazeFavoriteList());
		setFriendList(initializeFriendList());
		//setHistoryList(initializeTripHisytoryList());
		//lastRequestList = getFriendList();
		
		/*XMPP CONNECT*/
		connector = new XMPPConnector(server, password, userName , session);
		connector.startListen(context);
	}
	
	
    public ArrayList<HashMap<String, String>> initiliazeFavoriteList ()
    {
		/*Get User Friend List*/
    	PropertyInfo[] p=new PropertyInfo[1];
		p[0]=new PropertyInfo();
		p[0].setType(String.class);
		p[0].setName("session");
		p[0].setValue(session);
		
		/*Favorite List*/
		String res =wsHelper.CallWSFunction(MainActivity.nameSpace, MainActivity.url, "favoriteList", "urn:User#favoriteList", p);
		setFavoriteList(wsHelper.JsonToArrayList(res));
		
		return getFavoriteList();
    }
    
    public ArrayList<HashMap<String, String>> initializeFriendList ()
    {
		/*Get User Friend List*/
    	PropertyInfo[] p=new PropertyInfo[1];
		p[0]=new PropertyInfo();
		p[0].setType(String.class);
		p[0].setName("session");
		p[0].setValue(session);
		
		/*Friend List*/
		String res=wsHelper.CallWSFunction(MainActivity.nameSpace, MainActivity.url, "getFriendList", "urn:User#getFriendList", p);
		setFriendList(wsHelper.JsonToArrayList(res));
		return getFriendList();
    }

    public ArrayList<HashMap<String, String>> initializeTripHisytoryList ()
    {
		/*Get User Friend List*/
    	PropertyInfo[] p=new PropertyInfo[1];
		p[0]=new PropertyInfo();
		p[0].setType(String.class);
		p[0].setName("session");
		p[0].setValue(session);
		
		/*Friend List*/
		/*String res=wsHelper.CallWSFunction(MainActivity.nameSpace, MainActivity.url, "getTripHistory", "urn:User#getFriendList", p);
		setFriendList(wsHelper.JsonToArrayList(res));
		*/
		return getHistoryList();
    }
    
	public ArrayList<HashMap<String, String>> getFriendList() {
		return friendList;
	}


	public void setFriendList(ArrayList<HashMap<String, String>> friendList) {
		this.friendList = friendList;
	}


	public ArrayList<HashMap<String, String>> getFavoriteList() {
		return favoriteList;
	}


	public void setFavoriteList(ArrayList<HashMap<String, String>> favoriteList) {
		this.favoriteList = favoriteList;
	}


	public ArrayList<HashMap<String, String>> getHistoryList() {
		return historyList;
	}


	public void setHistoryList(ArrayList<HashMap<String, String>> historyList) {
		this.historyList = historyList;
	}


	public ArrayList<HashMap<String, String>> getLastRequestList() {
		return lastRequestList;
	}


	public void setLastRequestList(ArrayList<HashMap<String, String>> lastRequestList) {
		this.lastRequestList = lastRequestList;
	}
	
}
